package com.test.antlr4.calculator;

import com.test.antlr4.command.CommandLexer;
import com.test.antlr4.command.CommandParser;
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CommonTokenStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @className: Main
 * @Description:
 * @Author: wangyifei
 * @Date: 2025/5/21 17:35
 */
public class Main {
    private static Logger logger = LoggerFactory.getLogger(Main.class);

    public static void main(String[] args) {

        String expr = "1 + (8 + 2) * 2 + 12/3 + sum(1->3)";
        CalculatorLexer lexer = new CalculatorLexer(CharStreams.fromString(expr));
        CommonTokenStream tokens = new CommonTokenStream(lexer);
        CalculatorParser cal = new CalculatorParser(tokens);
        CalculatorParser.ExprContext expr1 = cal.expr();
        CalculatorVisitorImpl visitor = new CalculatorVisitorImpl();
        System.out.println(visitor.visit(expr1));
        System.out.println(1 + (8 + 2) * 2 + 12/3);
    }
}
